﻿//V.1.2 wachirapan
//clear Data checkbox from storeg
//transction_SaveData add option DialogConfirm
////============================================ฟังชั้นบันทึกข้อมูล=====================================================
(function($) {
    $.fn.transction_SaveData = function(settings) {
        var holder = $(this);
        var defaults = {
            URL_Save: "",           // Url สำหรับ Save
            Data: "",               // Data ที่ serialize แล้ว
            URL_SuccesReLoad: "",   // Url Reload จะใส่ ID ให้เมื่อ save ผ่าน แล้ว reload กลับไปหน้าเดิม
            URL_SuccessRedirectPage: "", //Url save ผ่านแล้ว ไปไหน
            CallBackFunction: false,
            CallBackFunction2: "",
            CallBackUnSeccess: "",
            IsShowDlgError: true,
            IsShowDlgList: false,
            titleAction:"Saving..",
            titleActionComplete:"Save Complete",
            messageAction: " ",
            messageActionComplete: " ",
            ContentName: "mainContent",
            DialogConfirm: {
                isShow: false,
                title: "confirm save data",
                message: "confirm save data",
                width: 400,
                height: 150
            },
            confirmFunction: "SaveData"

        }
        var options = jQuery.extend(defaults, settings);
        
        //แสดง dialog confirm หรือไม่
        var dialogConfirm = options.DialogConfirm;
        if (dialogConfirm.isShow) {
            //dialog Confirm
            $.fn.ConfirmDlg(dialogConfirm, options);
        } else {
            SaveData(options);
        }

   };
})(jQuery);

function SaveData(options){
        //--- requestTime
        var dateTime = new Date();                  
        dateTime = formatDateTime(dateTime);
        //options.URL_Save = options.URL_Save + "?requestTime="
        if(jQuery.type(options.Data) == "string")
        {
            options.Data +="&requestTime="+ dateTime;
        }else{
            var requestTime= {"requestTime":dateTime};
            var ExtraData = jQuery.extend(options.Data, requestTime);
            options.Data = ExtraData;
        }
        //---- end requestTime

        if ($(".validateMes").size() == 0) {
            $.blockUI({
                theme: true, // true to enable jQuery UI support
                title: options.titleAction, // only used when theme == true
                message: options.messageAction,
                overlayCSS:  {
		            backgroundColor: '#000',
		            opacity:	  	 0.5,
		            cursor:		  	 'wait'
	            }
            });
            $.post(options.URL_Save, options.Data, function(data) {
                if (data.success) {
                    //$("body").unblock(); //unblock and block
                    var titleSaveComplete = options.titleActionComplete
                    var messageSaveComplete = options.messageActionComplete
                    //fix top position
                    var scrollTopPoition = $(document).scrollTop()
                    moveScrollTop = (Number(scrollTopPoition) + $(window).height() / 2) - 50;
                    //
                    $.unblockUI();
                    $.blockUI({
                        theme: true, // true to enable jQuery UI support
                        title: titleSaveComplete, // only used when theme == true
                        message: messageSaveComplete,
                        timeout: 2000,
                        overlayCSS:  {
		                    backgroundColor: '#000',
		                    opacity:	  	 0.5,
		                    cursor:		  	 'wait'
	                    },
                        onUnblock: function() {
                            if (options.URL_SuccesReLoad != null && options.URL_SuccesReLoad != "") {
                                eval(options.URL_SuccesReLoad)(data);
                            }
                            else if (options.URL_SuccessRedirectPage != null && options.URL_SuccessRedirectPage != "") {
                                ReDirectPage(options);
                            }
                            else if (options.CallBackFunction2 != null && options.CallBackFunction2 != "") {
                                eval(options.CallBackFunction2)(data);
                            }
                            else if (options.CallBackFunction != null && options.CallBackFunction != "") {
                                eval(options.CallBackFunction);
                            }
                        }
                        //fix top position
                            , centerY: false, themedCSS: { top: moveScrollTop + 'px' }
                        //
                    }); //end block del
                }
                else {
                    //$("body").unblock(); //unblock and block
                    $.unblockUI();
                    $.blockUI({
                        theme: true, // true to enable jQuery UI support
                        title: "Save Error", // only used when theme == true
                        message: "Pleasewait..",
                        timeout: 2000,
                        overlayCSS:  {
		                    backgroundColor: '#000',
		                    opacity:	  	 0.5,
		                    cursor:		  	 'wait'
	                    },
                        onUnblock: function() {
                                if (options.IsShowDlgError) {
                                    if (options.IsShowDlgList) {
                                        //show error List Detail
                                        var obj = {
                                            dlgName: "OpenFrameTransactionDlg", autoDIV: true,
                                            titleCaption: "Save Alert Message", width: 800, height: 500, resizable: true, Modal: true,
                                            closeCallback: options.CallBackUnSeccess, openCallback: "", IsShowDlgList: options.IsShowDlgList
                                        }
                                        OpenFrameTransactionDlg(obj, data);
                                        if (options.CallBackFunction2 != null && options.CallBackFunction2 != "") {
                                            eval(options.CallBackFunction2)(data);
                                        }
                                    } else {
                                        var obj = {
                                            dlgName: "OpenFrameTransactionDlg", autoDIV: true,
                                            titleCaption: "Save Alert Message", width: 500, height: 190, resizable: true, Modal: true,
                                            closeCallback: options.CallBackUnSeccess, openCallback: ""
                                        }
                                        OpenFrameTransactionDlg(obj, data);
                                        if (options.CallBackFunction2 != null && options.CallBackFunction2 != "") {
                                            eval(options.CallBackFunction2)(data);
                                        }
                                    }
                                }else{
                                    if (options.CallBackUnSeccess != null && options.CallBackUnSeccess != "") {
                                        eval(options.CallBackUnSeccess) (data);
                                    }
                                }
                        }
                    });
                }
            })                    // end post
            .fail(function(jqXHR,textStatus,errorThrown) {
                alert(ShowjqXHRErrorMsg(jqXHR.responseText));
                $.unblockUI();
                //$("body").unblock(); //unblock and block
            });
        }

}

function ReDirectPage(options) {
    window.location = options.URL_SuccessRedirectPage;
}

//save ตัวการ submit
(function($) {
    $.fn.transction_Submit = function(settings) {
        var holder = $(this);
        var defaults = {
            URL_Save: "",           // Url สำหรับ Save
            ExtraData: "",               // Data Json ที่ไม่ได้เกิดจาก from
            Type: 'post',
            Target: '_self',
            URL_SuccesReLoad: "",   // Url Reload จะใส่ ID ให้เมื่อ save ผ่าน แล้ว reload กลับไปหน้าเดิม
            URL_SuccessRedirectPage: "", //Url save ผ่านแล้ว ไปไหน
            titleAction:"Saving..",
            titleActionComplete:"Save Complete",
            messageAction: " ",
            messageActionComplete: " ",
            CallBackFunction: false,
            CallBackUnSeccess: "",
            IsShowDlgList: false,
            ContentName: "mainContent",
             DialogConfirm: {
                isShow: false,
                title: "confirm save data",
                message: "confirm save data",
                width: 400,
                height: 150
            },
            confirmFunction: "SaveDataSubmit"
        };
        var errorMsg = "";
        if($(holder).size() == 0)
        {
            errorMsg = "transction_Submit : have not holder";
            alert(errorMsg);
        }
        var options = jQuery.extend(defaults, settings);
        //แสดง dialog confirm หรือไม่
        var dialogConfirm = options.DialogConfirm;
        $("body").data("transction_Submit_holder",holder);
        if (dialogConfirm.isShow) {
            //dialog Confirm
            $.fn.ConfirmDlg(dialogConfirm, options);
        } else {
            try{
                SaveDataSubmit(options);
            }
            catch(e)
            {
                console.log(e.message);
            }
        }

    }; //end $.fn.transction_Submit
})(jQuery);

function SaveDataSubmit(options)
{
    
    var holder = $("body").data("transction_Submit_holder");
    var pageBody = "body";
    //--- requestTime
    var dateTime = new Date();                   
    dateTime = formatDateTime(dateTime);
    var requestTime= {"requestTime":dateTime};
    var ExtraData = jQuery.extend(options.ExtraData, requestTime);
    options.ExtraData = ExtraData;
    //---- end requestTime
    if ($(holder).find(".validateMes").size() == 0) {
        try{
            $(holder).jNumeric('unset');
        }catch(e){}
        $.blockUI({
        //$(pageBody).block({
            theme: true, // true to enable jQuery UI support
            title: options.titleAction,
            message: options.messageAction,
            overlayCSS:  {
		        backgroundColor: '#000',
		        opacity:	  	 0.5,
		        cursor:		  	 'wait'
	        }
        });
        $(holder).ajaxSubmit({
            url: options.URL_Save,
            type: options.Type,
            target: options.Target,
            data: options.ExtraData,
            dataType: 'json',
            success: function(data) {
                if (data.success) {
                    try{
                        $(holder).jNumeric('init');
                    }catch(e){
                        console.log(e.toString());
                    }
                    var titleSaveComplete = options.titleActionComplete
                    var messageSaveComplete = options.messageActionComplete
                    //fix top position
                    var scrollTopPoition = $(document).scrollTop()
                    moveScrollTop = (Number(scrollTopPoition) + $(window).height() / 2) - 50;
                    //
                    HideBlockMsg();
                    $.blockUI({
                    //$(pageBody).block({ //block
                        theme: true, // true to enable jQuery UI support
                        title: titleSaveComplete, // only used when theme == true
                        message: messageSaveComplete,
                        timeout: 2000,
                        overlayCSS:  {
		                    backgroundColor: '#000',
		                    opacity:	  	 0.5,
		                    cursor:		  	 'wait'
	                    },
                        onUnblock: function() {
                            if (options.URL_SuccesReLoad != null && options.URL_SuccesReLoad != "") {
                                eval(options.URL_SuccesReLoad)(data);
                            }
                            else if (options.URL_SuccessRedirectPage != null && options.URL_SuccessRedirectPage != "") {
                                ReDirectPage(options);
                            }
                            else if (options.CallBackFunction != null && options.CallBackFunction != "") {
                                eval(options.CallBackFunction);
                            }
                            $.unblockUI(); 
                        }
                        //fix top position
                            , centerY: false, themedCSS: { top: moveScrollTop + 'px' }
                        //
                    }); //end block del
                }
                else {
                    try{
                        $(holder).jNumeric('init');
                    }catch(e){}
                    HideBlockMsg();
                    //$.unblockUI();
                    $.blockUI({
                    //$(pageBody).block({ //block
                        theme: true, // true to enable jQuery UI support
                        title: "Save Error", // only used when theme == true
                        message: "Pleasewait..",
                        timeout: 2000,
                        overlayCSS:  {
		                    backgroundColor: '#000',
		                    opacity:	  	 0.5,
		                    cursor:		  	 'wait'
	                    },
                        onUnblock: function() {
                            if (options.CallBackUnSeccess != null && options.CallBackUnSeccess != "" && options.IsShowDlgList != true) {
                                eval(options.CallBackUnSeccess);
                            }
                            else {
                                if (options.IsShowDlgList) {
                                    //show error List Detail
                                    var obj = {
                                        dlgName: "OpenFrameTransactionDlg", autoDIV: true,
                                        titleCaption: "Save Alert Message", width: 800, height: 500, resizable: true, Modal: true,
                                        closeCallback: options.CallBackUnSeccess, openCallback: "", IsShowDlgList: options.IsShowDlgList
                                    }
                                    OpenFrameTransactionDlg(obj, data);
                                } else {
                                    var obj = {
                                        dlgName: "OpenFrameTransactionDlg", autoDIV: true,
                                        titleCaption: "Save Alert Message", width: 500, height: 190, resizable: true, Modal: true,
                                        closeCallback: options.CallBackUnSeccess, openCallback: ""
                                    }
                                    OpenFrameTransactionDlg(obj, data);
                                }
                                //$("div.errorMes").html("<b>" + data.overallResult.Status + "</b><br>" + data.overallResult.Errors[0].Message).show(500);
                            }
                        } //end onUnblock
                    });
                } // data.success

            } // success
            ,error: function(jqXHR,textStatus,errorThrown ){
                //alert(jqXHR.responseText.find("title").text() + ":"+ textStatus +":" + errorThrown);
                alert(ShowjqXHRErrorMsg(jqXHR.responseText));
                $.unblockUI(); 
                //$(pageBody).unblock(); //unblock and block
            }
        }); //end ajaxSubmit
    }
}

(function($) {
    $.fn.transction_DeleteData = function(settings) {
        var holder = $(this);
        var defaults = {
            URL_Save: "",           // Url สำหรับ Save
            Data: "",               // Data ที่ serialize แล้ว
            URL_SuccesReLoad: "",   // Url Reload จะใส่ ID ให้เมื่อ save ผ่าน แล้ว reload กลับไปหน้าเดิม
            URL_SuccessRedirectPage: "", //Url save ผ่านแล้ว ไปไหน
            CallBackFunction: false,
            CallBackUnSeccess: "",
            titleAction:"Deleting..",
            titleActionComplete:"Delete Complete",
            messageAction: " ",
            messageActionComplete: " ",

            DialogConfirm: {
                isShow: false,
                title: "ยืนยันการลบ",
                message: "ยืนยันการลบ",
                width: 400,
                height: 180
            },
            confirmFunction: "DeleteDataPlugIn",
            IsShowDlgList: false
        }
        var options = jQuery.extend(defaults, settings);
        //แสดง dialog confirm หรือไม่
        var dialogConfirm = options.DialogConfirm;
        if (dialogConfirm.isShow) {
            //dialog Confirm
            $.fn.ConfirmDlg(dialogConfirm, options);
        } else {
            DeleteDataPlugIn(options);
        }

    };
})(jQuery);

//
function DeleteDataPlugIn(options) {
    if ($(".validateMes").size() == 0) {
        $.blockUI({
            theme: true, // true to enable jQuery UI support
            title: options.titleAction,
            message: options.messageAction,
            overlayCSS:  {
		        backgroundColor: '#000',
		        opacity:	  	 0.5,
		        cursor:		  	 'wait'
	        }
        });
        //--- requestTime
        var dateTime = new Date();                  
        dateTime = formatDateTime(dateTime);
        //options.URL_Save = options.URL_Save + "?requestTime="
        if(jQuery.type(options.Data) == "string")
        {
            options.Data +="&requestTime="+ dateTime;
        }else{
            var requestTime= {"requestTime":dateTime};
            var ExtraData = jQuery.extend(options.Data, requestTime);
            options.Data = ExtraData;
        }
        //---- end requestTime
        $.post(options.URL_Save, options.Data, function(data) {
            if (data.success) {
                //$("body").unblock(); //unblock and block
                var titleActionComplete = options.titleActionComplete;
                var messageActionComplete = options.messageActionComplete;
                //fix top position
                var scrollTopPoition = $(document).scrollTop()
                moveScrollTop = (Number(scrollTopPoition) + $(window).height() / 2) - 50;
                //
                HideBlockMsg();
                $.blockUI({
                //$("body").block({ //block
                    theme: true, // true to enable jQuery UI support
                    title: titleActionComplete, // only used when theme == true
                    message: messageActionComplete,
                    timeout: 1000,
                    overlayCSS:  {
		                backgroundColor: '#000',
		                opacity:	  	 0.5,
		                cursor:		  	 'wait'
	                },
                    onUnblock: function() {
                        if (options.URL_SuccesReLoad != null && options.URL_SuccesReLoad != "") {
                            eval(options.URL_SuccesReLoad)(data);
                        }
                        else if (options.URL_SuccessRedirectPage != null && options.URL_SuccessRedirectPage != "") {
                            ReDirectPage(URL_SuccessRedirectPage);
                        }
                        else if (options.CallBackFunction != null && options.CallBackFunction != "") {
                            eval(options.CallBackFunction);
                        }
                    }
                    //fix top position
                            , centerY: false, themedCSS: { top: moveScrollTop + 'px' }
                    //
                }); //end block del
            }
            else {
                //$("body").unblock(); //unblock and block
                HideBlockMsg();
                $.blockUI({
                //$("body").block({ //block
                    theme: true, // true to enable jQuery UI support
                    title: "Delete Error", // only used when theme == true
                    message: " ",
                    timeout: 1000,
                    overlayCSS:  {
		                backgroundColor: '#000',
		                opacity:	  	 0.5,
		                cursor:		  	 'wait'
	                },
                    onUnblock: function() {
                        if (options.IsShowDlgList) {
                            var obj = {
                                dlgName: "OpenFrameTransactionDlg", autoDIV: true,
                                titleCaption: "Delete Alert Message", width: 800, height: 500, resizable: true, Modal: true,
                                closeCallback: options.CallBackUnSeccess, openCallback: "", IsShowDlgList: options.IsShowDlgList
                            }
                        }
                        else {
                            var obj = {
                                dlgName: "OpenFrameTransactionDlg", autoDIV: true,
                                titleCaption: "Delete Alert Message", width: 520, height: 190, resizable: true, Modal: true,
                                closeCallback: options.CallBackUnSeccess, openCallback: "", IsShowDlgList: options.IsShowDlgList
                            }
                        }
                        OpenFrameTransactionDlg(obj, data);
                        //$("div.errorMes").html("<b>" + data.overallResult.Status + "</b><br>" + data.overallResult.Errors[0].Message).show(500);
                    }
                    
                });
            }
        });                     // end post
    }
} //end function DeleteData
/* dialog control*/
function OpenFrameTransactionDlg(settings, data) {
    //dlg, titleCaption, w, h, url, Modal, autoDIV, closeOther, closeCallback, openCallback
    var defaults = {
        dlgName: "",
        autoDIV: true,
        url: "",
        dataSend: "",
        titleCaption: "",
        width: "",
        height: "",
        Modal: true,
        resizable: true,
        closeDlgOtherAll: false,
        closeCallback: "",
        openCallback: "",
        zIndex: 1999,
        IsShowDlgList: false
    };
    var options = jQuery.extend(defaults, settings);
    var lastScroll = $(".ui-layout-center:first").scrollTop();

    if (options.autoDIV) {
        if ($("body").find("div#" + options.dlgName).size() == 0) {
            $("body").append('<div id="' + options.dlgName + '"></div>');
        }
    }
    var dlgTemp = $('#' + options.dlgName);
    if (!options.Modal) {
        options.Modal = false;
    }
    //clear all
    if (options.closeDlgOtherAll) {
        clearAllDialogMarkup();
    }

    dlgTemp.dialog({
        autoOpen: false,
        modal: options.Modal,
        show: 'clip', hide: 'clip',
        width: options.width, height: options.height, position: 'center',
        title: options.titleCaption, resizable: false,
        zIndex: options.zIndex,
        resizable: options.resizable,
        position: { my: "center", at: "center", of: window },
        bgiframe: true,
        close: function(event, ui) {
            //clear dialog on close
            if (options.autoDIV) {
                //clearDialogMarkup("div#" + options.dlg);
                closeDlgFrame("options.dlgName");
                $("div#" + options.dlgName).remove();
            }
            //calback
            if (options.closeCallback != "") { eval(options.closeCallback) (data); }
            //scroll to last position
            $(".ui-layout-center:first").scrollTop(lastScroll);
            //
        },
        open: function(event, ui) {
            var strHtml = "";
            strHtml = "<div id=\"AlertMsg\" style=\"word-wrap: break-word; text-align:left; width:95%;padding:20px 10px 20px 10px;\"></div><span></span>";
            strHtml += "<div class=\"buttonHolder\" align=center><span class=\"closeButton Button\">Close Windows</span></div></center>";
            $(this).append("" + strHtml + "");

            if (options.IsShowDlgList == true) {

                WriteResultsList("#OpenFrameTransactionDlg:last", data, options);
            }
            else {
                WriteResults("#OpenFrameTransactionDlg:last", data);
            }
            CloseAlertErrorDlgButton("#OpenFrameTransactionDlg:last", options,data);
            //AssignButton($(this), optionsData);
            //AssignCutText('.cutword'); //ตัดคำให้พอดีคอลัมน์แล้วเติม... แต่ต้องกำหนด width ให้ คอลัมน์นั้นด้วย
        }
    });
    dlgTemp.dialog('open');
}

function CloseAlertErrorDlgButton(holder,options,data) {
    $(holder).find(".closeButton").button({ icons: { primary: 'ui-icon-close'} }).click(function() {
        //alert(options.closeCallback +"-"+ data);
        $("body").data("ReturnResult",data);
        if (options.closeCallback != "") { eval(options.closeCallback) (data); }
        closeDlgFrame("options.dlgName");
        $("div#" + options.dlgName).remove();
        
    });
}
function WriteResults(holder,data) {
    $(holder).find("#AlertMsg").html(data.errorContainer.errorList[0].errorKey + "  <br>" + data.errorContainer.errorList[0].errorMsg);
}
function WriteResultsList(holder, data, options) {
    var strHtml = "";
    strHtml = "<table name='errorList' width='"+(options.width-50)+"'>";
    var errorMassageHeader = "Error Massage";
    //alert(JSON.stringify(data));
    if(data.errorContainer.errorList.length > 0){
        errorMassageHeader = data.errorContainer.errorList[0].errorType;
    }
    strHtml += "<tr><th>Key Name</th><th>"+errorMassageHeader+"</th></tr>";
    for(var i=0;i<data.errorContainer.errorList.length;i++)
    {
        strHtml += "<tr><td width='30%'>" + data.errorContainer.errorList[i].errorKey + "</td><td width='70%'>" + data.errorContainer.errorList[i].errorMsg + "</td></tr>";
    }
    strHtml +="</table>";
    $(holder).find("#AlertMsg").html(strHtml);
    //AssignTableClass($("table[name='errorList']"), true);
    $("table[name='errorList']").assignTableClass({
        makeHover: false,
        emptyCaption: "",
        white_space: "nowrap",
        colspan: 0,
    });
}


//================ Dialog For Show Data ===============
(function($) {
    $.fn.ConfirmDlg = function(settings, optionData) {
        var holder = $(this);
        var defaults = {
            message: "",
            dlgName: "dlgConfirm",
            autoDIV: true,
            url: "",
            dataSend: "",
            titleCaption: "",
            width: 400,
            height: 160,
            Modal: true,
            resizable: true,
            closeDlgOtherAll: false,
            closeCallback: "",
            openCallback: "",
            zIndex: 999,
            cancelFunction:"",
            confirmFunction:"",
            TextConfirm: "OK",
            TextCancel : "Cancel",
            showIconButton:"true",
        }
        
        var options = jQuery.extend(defaults, settings);
        if(options.confirmFunction != ""){
            optionData = {confirmFunction : options.confirmFunction,cancelFunction : options.cancelFunction,showIconButton: options.showIconButton}
            //alert(optionData.confirmFunction);
        }



        var lastScroll = $(".ui-layout-center:first").scrollTop();
        if (options.autoDIV) {
            if ($("body").find("div#" + options.dlgName).size() == 0) {
                $("body").append('<div id="' + options.dlgName + '"></div>');
            }
        }
        var dlgTemp = $('#' + options.dlgName);
        if (!options.Modal) {
            options.Modal = false;
        }
        //clear all
        if (options.closeDlgOtherAll) {
            clearAllDialogMarkup();
        }
        dlgTemp.dialog({
            autoOpen: false,
            modal: options.Modal,
            show: 'clip', hide: 'clip',
            title: options.titleCaption, resizable: false,
            zIndex: options.zIndex,
            resizable: options.resizable,
            bgiframe: true,
            position: { my: "center", at: "center", of: window },
            width: options.width, height: options.height,
            close: function(event, ui) {
                //clear dialog on close
                if (options.autoDIV) {
                    clearDialogMarkup("div#" + options.dlg);
                }
                //calback
                if (options.closeCallback) { eval(options.closeCallback) }
                //scroll to last position
                $(".ui-layout-center:first").scrollTop(lastScroll);
                //
            },
            open: function(event, ui) {
                //วาด DataGride ข้อมูลที่เลือก
                $(this).html("");
                $(this).html("<div  style=\"text-align:center;padding:20px 0px 10px 0px;\">" + options.message + "</div><div class='blockManageButton' style=\"text-align:center;\"></div><div class='content'></div>");
                $(this).find('.blockManageButton').append("<span id=\"confirmButton\" class=\"confirmButton button\">"+options.TextConfirm+"</span><span id=\"cancelButton\" class=\"cancelButtonConfirmDlg button\">"+options.TextCancel+"</span>");
                AssignButton($(this), optionData);
            }
        });
        dlgTemp.dialog('open');


        function AssignButton(Holder, optionData) {
            var iconCancel = 'ui-icon-cancel';
            var iconCheck = 'ui-icon-check';
            if(optionData.showIconButton == false)
            {
                var iconCancel = '';
                var iconCheck = '';
            }
            $(Holder).find("#cancelButton").button({ icons: { primary: iconCancel} }).click(function() {
                if(optionData.cancelFunction != undefined && optionData.cancelFunction != "")
                {
                    CloseDlg();
                    eval(optionData.cancelFunction) ();
                }else{
                    CloseDlg();
                }
            });
            $(Holder).find("#confirmButton").button({ icons: { primary: iconCheck} }).click(function() {
                if (optionData.confirmFunction != undefined && optionData.confirmFunction != "") {
                    CloseDlg();
                    eval(optionData.confirmFunction)(optionData);
                }
                else {
                    CloseDlg();
                }
            });
        }
        function CloseDlg() {
            JclearDialogMarkup("div#" + "dlgConfirm");
            var dlgTemp = $("div#" + "dlgConfirm");
            dlgTemp.fadeTo('slow', 0, function() {
                dlgTemp.dialog('close');
            });
            //dlgTemp.dialog('close');
            dlgTemp.remove();
        }
        function JclearDialogMarkup(dlg) {
            $(dlg).parent().remove().end().remove();

        }
    };
})(jQuery);


(function($) {
   $.fn.serializeObject = function(settings) {
       var o = {};
       var a = this.serializeArray();
       $.each(a, function() {
           if (o[this.name]) {
               if (!o[this.name].push) {
                   o[this.name] = [o[this.name]];
               }
               o[this.name].push(this.value || '');
           } else {
               o[this.name] = this.value || '';
           }
       });
       return o;
   };
})(jQuery);

function HideBlockMsg()
{
    $(document).find(".blockMsg:first").css({"display":"none"});
}

